package com.sz.ruichar.service.beans;

import com.sz.ruichar.entity.beans.TUserInfo;
import com.sz.ruichar.service.mapper.beans.TUserInfoMapper;
import com.sz.ruichar.interfs.beans.ITUserInfoService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户个人信息表 服务实现类
 * </p>
 *
 * @author 5beans
 * @since 2017-12-26
 */
@Service
public class TUserInfoServiceImpl extends ServiceImpl<TUserInfoMapper, TUserInfo> implements ITUserInfoService {
	
	@Autowired
	TUserInfoMapper userInfoMapper;

	@Override
	public TUserInfo getUserInfo(String openId) {
		TUserInfo info = new TUserInfo();
		info.setOpenid(openId);
		info = userInfoMapper.selectOne(info);
		return info;
	}

	@Override
	public void saveUserInfo(TUserInfo userInfo) {
		TUserInfo exitInfo = this.getUserInfo(userInfo.getOpenid());
		if(null == exitInfo){
			userInfo.insert();
		}else{
			userInfo.setId(exitInfo.getId());
			userInfo.updateById();
		}
	}
	
}
